# 代码编写者： 李朔
# 开发时间： 2021/7/21 9:36

flowerbed=[0,0,1,0,0]

def canPlaceFlowers(flowerbed,n):
    flowerbed_len=len(flowerbed)
    i=0
    while i<flowerbed_len:
        #当前位置未种花
        if flowerbed[i]==0:
            if flowerbed_len>2:
                if i==0 and flowerbed[i+1]==0:
                    flowerbed[i]=1
                    n-=1
                elif i==flowerbed_len-1 and flowerbed[i-1]==0:
                    flowerbed[i]=1
                    n-=1
                elif i>0 and i<flowerbed_len-1 and flowerbed[i+1]==0 and flowerbed[i-1]==0:
                    flowerbed[i]=1
                    n-=1
                else:
                    pass
            elif flowerbed_len==2:
                if i==0 and flowerbed[i+1]==0:
                    flowerbed[i]=1
                    n-=1
                elif i==flowerbed_len-1 and flowerbed[i-1]==0:
                    flowerbed[i]=1
                    n-=1
            else:
                if flowerbed[i]==0:
                    flowerbed[i]=1
                    n-=1
        i+=1
    if n<=0:
        return True
    else:
        return False

print(canPlaceFlowers(flowerbed,1))




